package com.wiloon.java8x.dataImport;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/5/29.
 */
public class DataRowImpl implements DataRow {
    protected List<DataCell> dataCells;
    protected int cellCount;

    @Override
    public void addDataCell(DataCell dataCell) {
        if (dataCells == null) {
            dataCells = new ArrayList<DataCell>();
        }
        dataCells.add(dataCell);
    }

    @Override
    public List<DataCell> getDataCells() {
        return dataCells;
    }

    @Override
    public int size() {
        return dataCells.size();
    }

    @Override
    public DataCell getDataCell(int index) {
        return dataCells.get(index);
    }

    @Override
    public boolean isMultiValueMatch() {
        boolean isMultiValue = true;
        int tmpCellCount = -1;
        for (DataCell dataCell : dataCells) {
            int cellCount = ((DataCellStringMultiValue) dataCell).getValueCount();
            if (dataCell instanceof DataCellStringMultiValue) {
                if (tmpCellCount == -1) {
                    tmpCellCount = ((DataCellStringMultiValue) dataCell).getValueCount();
                } else if (tmpCellCount != cellCount) {
                    isMultiValue = false;
                }
            }
        }
        this.cellCount = tmpCellCount;
        return isMultiValue;
    }

    public int getCellCount() {
        return cellCount;
    }

    public void setCellCount(int cellCount) {
        this.cellCount = cellCount;
    }

    public void setDataCells(List<DataCell> dataCells) {
        this.dataCells = dataCells;
    }
}
